#!/bin/bash 
#slipt kingdom horizon file,format=CI7 horizon file
line=25
awk '/PROFILE/{x="'$line'basement"++i;}$1~/[[:digit:]+]/{printf("%.12lg %.12lg %.12lg %.12lg \n",$4,$3*0.001,$1,$2) > x;}' ${line}_basement.dat #basement
dldir=${line}_basement
[ -d ${dldir} ] && rm -r ${dldir} #remove exist ${dldir},if not, when run twice of the script,the files will append twice
mkdir ${dldir}
mv ${line}basement* ${dldir}
cd ${dldir}
for i in ./${line}basement*
do
awk '{printf("%.12lg %.12lg %.12lg %.12lg %.12lg \n",$1,$1,$2,$3,$4)}' $i > tmp.txt  # duplicate raw 1
awk '{tmp = $2; $2 = prev; prev = tmp; print}' tmp.txt > tmp1.txt    # shift raw 2 upward #core
awk  '{printf("%.12lg %.12lg %.12lg %.12lg %.12lg %.12lg \n",$1-$2,$1,$2,$3,$4,$5)}' tmp1.txt  > tmp2.txt  # calculate subtract
awk '$1 ~ /[^1]/ {x="WH"++i;}{printf("%.12lg %.12lg %.12lg %.12lg \n",$2,$4,$5,$6) >> x;close(x)}' tmp2.txt # ^is the not in regex!
sed -i '' '1d' WH1 # '' used for mac, sed -i '1d' WH1 for linux
done
rm tmp*
